<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}
/**
 * SendsmsClass类
 * send(tel)发送短信函数
 * return true/flase
 *
 */

class SendsmsClass {
	var $httpurl;
	var $method;
	var $ok;
	function __construct(){
		//设置全局变量 全部变量在系统设置读取 留作后来修改
		global $cfg_sms_httpurl,$cfg_sms_method,$cfg_sms_ok;
		$this->httpurl=$cfg_sms_httpurl;
		$this->method=$cfg_sms_method;
		$this->ok=$cfg_sms_ok;
	}
	function SendsmsClass() {
		$this->__construct();
	}
	/**
	 * 发送短信操作
	 *
	 * @param 号码 $tel
	 * @param 参数 $post
	 * @return true/false
	 */
	function send($tel,$msg,$post = null)
	{
		if(isset($this->httpurl)&& isset($tel)){
			//替换电话号码
			$this->httpurl=str_replace("[tel]",$tel,$this->httpurl);
			$this->httpurl=str_replace("[msg]",$msg,$this->httpurl);
			if($this->method=="GET"){
				$replyinfo=$this->Get($tel);
				if($replyinfo==$this->ok)return true;
					else return false;
			}elseif ($this->method=="POST"){
				$replyinfo=$this->Post($tel,$post);
				if($replyinfo==$this->ok)return true;
					else return false;
			}else return false;
		}return false;
	}
	
	function Post($pmb, $post = null)
	{
     $context = array();
     if (is_array($post))
     {
         ksort($post);

         $context['http'] = array
         (
             'timeout'=>60,
             'method' => 'POST',
             'content' => http_build_query($post, '', '&'),
         );
     }
     return file_get_contents($this->httpurl, false, stream_context_create($context));
     //var_dump($http_response_header)
	}
	function Get($gmb)
	{
     $context = array();
     $context['http'] = array(
             'timeout'=>60,
             'method' => 'GET',
         );
		include_once(INC_PATH.'/httpdown.class.php');
		$htd=new HttpDown();
		$htd->OpenUrl($this->httpurl);
		return $htd->GetHtml();
   //  return file_get_contents($this->httpurl, false, stream_context_create($context));
     //var_dump($http_response_header);
	}
}

//调用演示
//$httpget=new SendsmsClass();
//var_dump($httpget->send("13613805057","内容"));


?>
